# autoresponder_app/views.py

from django.shortcuts import render
from .models import Question

def auto_responder(request):
    if request.method == 'POST':
        user_question = request.POST.get('user_question')
        question = Question.objects.filter(text__icontains=user_question).first()
        if question:
            response = question.answer
        else:
            response = "对不起，我不明白您的问题。"

        return render(request, 'autoresponder_app/response.html', {'response': response})

    return render(request, 'autoresponder_app/auto_responder.html')
